# -*- coding: utf-8 -*-
'''
# @Datetime: 2018/12/24
# @author: Zhang Yafei
'''
"""
__new__和__init__的区别
1.__new__:创建对象时调用，会返回当前对象的一个实例
  __init__:创建完对象后调用，对当前对象的一些实例初始化，无返回值
2、在类中，如果__new__和__init__同时存在，会优先调用__new__
3. If __new__() returns an instance of cls, then the new instance’s __init__() method will be invoked like __init__(self[, ...]), where self is the new instance and the remaining arguments are the same as were passed to __new__().
      如果__new__返回一个对象的实例，会隐式调用__init__
   If __new__() does not return an instance of cls, then the new instance’s __init__() method will not be invoked.
      如果__new__不返回一个对象的实例，__init__不会被调用
"""


class Obj(object):
    def __new__(self, *args, **kwargs):
        print('__new__')
        obj = super(Obj, self).__new__(self, *args, **kwargs)
        print(obj)
        return obj

    def __init__(self):
        print('__init__')
        # return 1


obj = Obj()

 
class Obj2(object):
    def __new__(self, *args, **kwargs):
        print('__new__')
        
    def __init__(self):
        print('__init__')


obj2 = Obj2()